package com.qj.platform.pay.mssm.utils;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhijie on 2016/12/20.
 */
public class MsJaxbDateAdapter extends XmlAdapter<String, Date> {
    static final String DATE_FORMAT = "yyyyMMddHHmmss";

    @Override
    public Date unmarshal(String v) throws Exception {
        if (v == null) {
            return null;
        }

        DateFormat format = new SimpleDateFormat(DATE_FORMAT);
        return format.parse(v);
    }

    @Override
    public String marshal(Date v) throws Exception {
        DateFormat format = new SimpleDateFormat(DATE_FORMAT);
        return format.format(v);
    }
}
